Font Library: ensure merged fontFace data is enconded as an array instead of an object #54435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
Why?
To fix a bug consisting of fontFace data being JSON encoded as an object ( {...} ) instead of an array ( [...] ).
When we remove duplicates, we could end up with missing sequential array keys in the fontFace list.
Because of the nature of PHP arrays and how they are encoded into JSON. In PHP, arrays can behave like indexed arrays or associative arrays (hashmaps). When they are encoded into JSON, indexed arrays become JSON arrays (e.g., [...]), while associative arrays become JSON objects (e.g., {...}).
The reason fontFace is being encoded as an object in your JSON output is due to the non-sequential keys.
How?
To ensure that fontFace is always encoded as a JSON array, I reset the keys of the
$unique_face
s array usingarray_values()
before assigning it to$merged_font['fontFace']
. This will reindex the keys and make sure they are sequential.Testing Instructions
Run PHP unit tests with and without calling
array_values()
on this line:The added test case should fail when
array_values()
is not used.